/***********************************************************
 *  File_Name  : XJDateTime.cpp
 *  File_Path   :
 *  File_Encode : UTF8
 *  Description : The date and time of operation class
 *
 *  OS : Linux, UNIX
 *  LastVersion  : 20240223
 *
 *  Author      : LiXiujie(李秀杰)
 *  Date        : 2024-2-23
 *  Version     : 20240223
 *  Description :
 *
 *  Edit Author :
 *  Edit Date   :
 *  Version     :
 *  Description :
 *
 ***********************************************************/
#include "XJUseTime.h"
#include "XJDateTime.h"
namespace XJUtilClass {

XJUseTime::XJUseTime(const std::string & name, int aWarnTime, 
	XJUseTimeWarnFun fun):mName(name),
	miBeginTime(XJDateTime::GetSystemMilliTime()),
	miWarnTime(aWarnTime),
	mpFun(fun) {
}

XJUseTime::~XJUseTime() {
	int64_t liUseTime =  XJDateTime::GetSystemMilliTime() - miBeginTime;
	if (miWarnTime && liUseTime >= miWarnTime && mpFun) {
		mpFun(mName, liUseTime);
	}
}

int64_t XJUseTime::ResetBegin() {
	int64_t liUseTime =  XJDateTime::GetSystemMilliTime() - miBeginTime;
	miBeginTime = miBeginTime + liUseTime;
	return liUseTime;
}

int64_t XJUseTime::GetUseTimeMS() {
	return XJDateTime::GetSystemMilliTime() - miBeginTime;
}

} /* namespace XJUtilClass */
